﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LabTurtorial
{
    public partial class LINQDemo : Form
    {
        public LINQDemo()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ConnectToTeacherByLinqDataContext dataTeacher = new ConnectToTeacherByLinqDataContext();
            //DataTable table = new DataTable();
            dataGridView1.DataSource = from t in dataTeacher.Teachers select t;
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("ID");
            dataTable.Columns.Add("Password");
            dataTable.Columns.Add("Name");
            ConnectToTeacherByLinqDataContext dataTeacher = new ConnectToTeacherByLinqDataContext();
            //var table = from t in dataTeacher.Teachers where( t.Name.Contains("giza")) select t;
            var table = from s in dataTeacher.Teachers select s;            
            foreach (var t in table)
            {
                DataRow row = dataTable.NewRow();
                row["ID"] = t.TeacherID.ToString();
                row["Password"] = t.Password.ToString();
                row["Name"] = t.Name.ToString();
                dataTable.Rows.Add(row);
            }
            dataGridView1.DataSource = dataTable;
        }
    }
}
